package com.example.design.shejimoshi.structure.compose;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description TODO
 * @date 2022/10/25 14:49
 * @Author liuzhihui
 * @Version 1.0
 */
public class Department extends HumanResource {
    List<HumanResource> subNodes = new ArrayList<>();

    public Department(Long id) {
        super(id);
    }

    @Override
    public double calculateSalary() {
        double totalSalary = 0;
        for (HumanResource subNode : subNodes) {
            totalSalary += subNode.calculateSalary();
        }
        this.salary = totalSalary;
        return totalSalary;
    }

    public void addSubNodes(HumanResource humanResource){
        subNodes.add(humanResource);
    }
}
